package com.test.kotlin.ui.adapter

import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import com.blankj.utilcode.util.ScreenUtils
import com.blankj.utilcode.util.SizeUtils
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.test.kotlin.R
import com.test.kotlin.bean.SpecialTopicData


class SpecialTopicAdapter :BaseQuickAdapter<SpecialTopicData,BaseViewHolder>(R.layout.layout_home_special_topic_item) {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder {
        var holder= super.onCreateViewHolder(parent, viewType)

        var view=holder.getView<View>(R.id.iv_topic_img)
        view.layoutParams.width=(ScreenUtils.getScreenWidth() - SizeUtils.dp2px(20f)) / 9 * 4
        view.requestLayout()
        return holder
    }
    override fun convert(holder: BaseViewHolder, item: SpecialTopicData) {
        with(item){
            var imgView=holder.getView<ImageView>(R.id.iv_topic_img)
            Glide.with(imgView)
                .load(poster)
                .placeholder(R.drawable.place_holder)
                .into(imgView)

            holder.setText(R.id.tv_topic_title,resName)
            holder.setText(R.id.tv_topic_sub,des)
        }
    }
}